<h2><%= t(:identity_request_from_host, :host => h(extract_host(@site.url))).html_safe %></h2>

<% if ax_store_request %>
<p><%= t(:trust_root_sends_some_personal_data, :trust_root => "<strong>#{h checkid_request.trust_root}</strong>").html_safe %><br />
<% if @site.user_confirm %>
<%= t(:select_information_to_accept) %></p>
<p class="note"><%= t(:attributes_will_be_added_to_persona, :persona => "<strong>#{h @site.user_confirm.title}</strong>",
  :choose_link => link_to_function(t(:choose_other_persona), 'Element.toggle("persona_select")')).html_safe %></p>
<% else %>
<p><%= t(:identity_request_missing_persona, :create_link => link_to(t(:create_persona_link), new_user_confirm_path(:return => decide_path))).html_safe %></p>
<% end %>

<% elsif sreg_request || ax_fetch_request %>
<p><%= t(:trust_root_requests_some_personal_data, :trust_root => "<strong>#{h checkid_request.trust_root}</strong>").html_safe %><br />
<% if @site.user_confirm %>
<%= t(:select_information_to_submit) %></p>
<p class="note"><%= t(:attributes_are_shown_from_persona, :persona => "<strong>#{h @site.user_confirm.title}</strong>").html_safe %><br />
<%= t(:to_submit_other_values_you_can_edit_or_choose,
  :edit_link => link_to(t(:edit_persona_link), edit_user_confirm_path(@site.user_confirm, :return => decide_path(:user_confirm_id => @site.user_confirm.id))),
  :choose_link => link_to_function(t(:choose_other_persona), 'Element.toggle("persona_select")')).html_safe %></p>
<% else %>
<p><%= t(:identity_request_missing_persona, :create_link => link_to(t(:create_persona_link), new_user_confirm_path(:return => decide_path))).html_safe %></p>
<% end %>
<% else %>
<p><%= t(:trust_root_requires_authentication, :trust_root => "<strong>#{h checkid_request.trust_root}</strong>").html_safe %></p>
<% end %>

<%= form_tag decide_path, :method => :get, :id => 'user_confirm_select', :style => 'display:none;' do %>

  <h3><%= t(:choose_persona_title) %></h3>
  <% unless current_user.user_confirm.empty? %>
  <div class="row">
    <select id="user_confirm_id" name="user_confirm_id">
      <%= options_from_collection_for_select(current_user.user_confirm, :id, :title, @site.user_confirm.id) %>
    </select>
  </div>
  <div>
    <%= submit_tag t(:choose_persona_submit) %> <%= t(:or) %>
    <%= link_to t(:create_new_persona_link), new_user_confirm_path(:return => decide_path) %>
  </div>
  <% end %>

<% end if sreg_request || ax_fetch_request || ax_store_request %>

<%= form_for @site, :url => complete_path do |f| %>

  <% if sreg_request || ax_fetch_request %>
  <table cellspacing="0">
    <tr>
      <th colspan="2"><h4><%= t(:requested_information_title) %></h4></th>
      <th class="disclosure"><%= t(:disclosure) %></th>
    </tr>
    <% (sreg_request.required + sreg_request.optional).each do |property| %>
    <% req_style = ""%>
    <% if property == "roles" || property == "oauthtoken"%>
     <% else %>
	     <tr>
	      <td><%= label_tag "site_sreg_#{property}", property_label_text(property) %></td>
	      <td><%= label_tag "site_sreg_#{property}", @site.user_confirm.property(property) %></td>
	      <td>
	        <%= check_box_tag "humble_site[sreg][#{property}]", @site.user_confirm.property(property), sreg_request.required.include?(property), :id => "site_sreg_#{property}", :class => sreg_request_for_field(property) %>
	        <%= label_tag "site_sreg_#{property}", sreg_request_for_field(property), :class => 'note' %>
	      </td>
	    </tr>
    <% end %>
    <% end if sreg_request %>
    <% ax_fetch_request.attributes.each do |property| %>
    <% supported = UserConfirm.attribute_name_for_type_uri(property.type_uri).nil? %>
    <tr>
      <td><%= label_tag "site_ax_fetch_#{property.ns_alias}", property_label_text(property.ns_alias) %></td>
      <td><%= label_tag "site_ax_fetch_#{property.ns_alias}", supported ? @site.user_confirm.property(property.type_uri) : t(:not_supported), :class => supported ? nil : 'note' %></td>
      <td>
        <%= check_box_tag "humble_site[ax_fetch][#{property.ns_alias}][value]", @site.user_confirm.property(property.type_uri), property.required, :id => "site_ax_fetch_#{property.ns_alias}", :class => ax_request_for_field(property), :disabled => !supported %>
        <%= hidden_field_tag "humble_site[ax_fetch][#{property.ns_alias}][type]", property.type_uri, :id => "site_ax_fetch_type_#{property.ns_alias}" %>
        <%= label_tag "site_ax_fetch_#{property.ns_alias}", ax_request_for_field(property), :class => 'note' %>
      </td>
    </tr>
    <% end if ax_fetch_request %>
  </table>
  <% end %>

  <% if ax_store_request %>
  <table cellspacing="0">
    <tr>
      <th colspan="2"><h4><%= t(:sent_information_title) %></h4></th>
      <th class="current"><%= t(:current) %></th>
      <th class="accept"><%= t(:accept) %></th>
    </tr>
    <% ax_store_request.data.each do |type_uri, value| %>
    <% if attribute = UserConfirm.attribute_name_for_type_uri(type_uri) %>
    <tr>
      <td><%= label_tag "site_ax_store_#{attribute}", property_label_text_for_type_uri(type_uri) %></td>
      <td><%= label_tag "site_ax_store_#{attribute}", value %></td>
      <td><%= label_tag "site_ax_store_#{attribute}", @site.user_confirm.property(type_uri) %></td>
      <td>
        <%= check_box_tag "humble_site[ax_store][#{attribute}][value]", value, false, :id => "site_ax_store_#{attribute}" %>
        <%= hidden_field_tag "humble_site[ax_store][#{attribute}][type]", type_uri, :id => "site_ax_store_type_#{attribute}" %>
      </td>
    </tr>
    <% end %>
    <% end %>
  </table>
  <% end %>

  <div>
    <% if sreg_request || ax_fetch_request || ax_store_request %>
    <%= f.hidden_field :user_confirm_id %>
    <%= f.hidden_field :url %>
    <% end %>

    <% if sreg_request || ax_fetch_request %>
    <%= submit_tag t(:trust_site_only_this_time), :name => 'temporary', :class => 'space' %>
    <%= submit_tag t(:always_trust_site), :name => 'always', :class => 'space' %>
    <% else %>
    <%= submit_tag t(:approve_request), :name => 'temporary', :class => 'space' %>
    <% end %>
    <%= submit_tag t(:cancel_request), :name => 'cancel' %>
  </div>

<% end unless current_user.user_confirm.empty? %>

